/**
 * Determine decimal places from step for consistent formatting.
 * Supports values like 0.1, 0.01 and scientific notation like 1e-3.
 */
export function getStepDecimalPlaces(n: number): number {
  if (!Number.isFinite(n) || n <= 0) return 0;
  const s = n.toString().toLowerCase();
  if (s.includes("e-")) {
    const parts = s.split("e-");
    const expo = Number(parts[1]);
    return Number.isFinite(expo) ? Math.max(0, expo) : 0;
  }
  const dot = s.split(".")[1];
  return Math.max(0, dot ? dot.length : 0);
}
